package com.jiazhong.basic.pack0517;

import lombok.SneakyThrows;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Arrays;

public class DemoC {
    // 自动处理异常
    @SneakyThrows
    public static void main(String[] args) {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql:///jiazhong_2025_2";
        String user = "root";
        String password = "a123456";
        Connection conn = DriverManager.getConnection(url, user, password);
        String sql = "insert into f values(1,'张三')";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.addBatch("insert into f values(2,'张三2')");
        ps.addBatch("insert into f values(3,'张三3')");
        ps.addBatch("insert into f values(4,'张三4')");
        ps.addBatch("insert into f values(5,'张三5')");
        // 统一的执行（还是mysql执行）
        int[] ints = ps.executeBatch();
        System.out.println(Arrays.toString(ints));
        ps.close();
        conn.close();
    }
}
